﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using GandA.Component.DataAccess.SQLServer;
using SACM.BusinessEntity;
using SACM.Common.Constantes;

namespace SACM.DAO
{
    public class DoctorServiceDAO
    {
        public static void Save(Doctor obj)
        {
            SQLParameterCollection paramsSql = new SQLParameterCollection();

            paramsSql.Add(new SQLParameter(Parametros.psNombre, obj.Nombre, SQLParameter.vEnumSqlDbType.VarChar, SQLParameter.vEnumParameterDirection.vInput));
            paramsSql.Add(new SQLParameter(Parametros.psApellidoPaterno, obj.ApellidoPaterno, SQLParameter.vEnumSqlDbType.VarChar, SQLParameter.vEnumParameterDirection.vInput));
            paramsSql.Add(new SQLParameter(Parametros.psApellidoMaterno, obj.ApellidoMaterno, SQLParameter.vEnumSqlDbType.VarChar, SQLParameter.vEnumParameterDirection.vInput));
            paramsSql.Add(new SQLParameter(Parametros.psCedulaProfesional, obj.CedulaProfesional, SQLParameter.vEnumSqlDbType.VarChar, SQLParameter.vEnumParameterDirection.vInput));
            paramsSql.Add(new SQLParameter(Parametros.psRFC, obj.RFC, SQLParameter.vEnumSqlDbType.VarChar, SQLParameter.vEnumParameterDirection.vInput));
            paramsSql.Add(new SQLParameter(Parametros.psDomicilioFiscal, obj.DomicilioFiscal, SQLParameter.vEnumSqlDbType.VarChar, SQLParameter.vEnumParameterDirection.vInput));
            paramsSql.Add(new SQLParameter(Parametros.psTelefono, obj.Telefono, SQLParameter.vEnumSqlDbType.VarChar, SQLParameter.vEnumParameterDirection.vInput));
            paramsSql.Add(new SQLParameter(Parametros.psIpMod, obj.IpMod, SQLParameter.vEnumSqlDbType.VarChar, SQLParameter.vEnumParameterDirection.vInput));
            paramsSql.Add(new SQLParameter(Parametros.pnIdUsuarioMod, obj.IdUsuarioMod, SQLParameter.vEnumSqlDbType.Int, SQLParameter.vEnumParameterDirection.vInput));
            paramsSql.Add(new SQLParameter(Parametros.pnIdDoctor, obj.IdDoctor, SQLParameter.vEnumSqlDbType.Int, SQLParameter.vEnumParameterDirection.vInput));
            paramsSql.Add(new SQLParameter(Parametros.pnIdEmpresa, obj.IdEmpresa, SQLParameter.vEnumSqlDbType.Int, SQLParameter.vEnumParameterDirection.vInput));
            paramsSql.Add(new SQLParameter(Parametros.pnIdSucursal, obj.IdSucursal, SQLParameter.vEnumSqlDbType.Int, SQLParameter.vEnumParameterDirection.vInput));

            try
            {
                DataSet ds = new SQL().ExecuteQueryStoreProcedure(General.SACM + ".spRegistraDoctor", paramsSql);
                obj.IdDoctor= SACM.Common.Util.Convert.ToInt(ds.Tables[0].Rows[0][Columnas.IdDoctor].ToString());
            }
            catch (SQLException ex)
            {
                throw new Exception(ex.Message);
            }
        }

        public static void Delete(Doctor obj)
        {
            SQLParameterCollection paramsSql = new SQLParameterCollection();

            paramsSql.Add(new SQLParameter(Parametros.pnIdDoctor, obj.IdDoctor, SQLParameter.vEnumSqlDbType.Int, SQLParameter.vEnumParameterDirection.vInput));
            paramsSql.Add(new SQLParameter(Parametros.pnIdEmpresa, obj.IdEmpresa, SQLParameter.vEnumSqlDbType.Int, SQLParameter.vEnumParameterDirection.vInput));
            paramsSql.Add(new SQLParameter(Parametros.pnIdSucursal, obj.IdSucursal, SQLParameter.vEnumSqlDbType.Int, SQLParameter.vEnumParameterDirection.vInput));

            try
            {
                new SQL().ExecuteNonQueryStoreProcedure(General.SACM + ".spEliminaDoctor", paramsSql);
            }
            catch (SQLException ex)
            {
                throw new Exception(ex.Message);
            }
        }
    }
}
